<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>花龙腾航 - 航班管理</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap');
        
        body {
            font-family: 'Noto Sans SC', sans-serif;
            background-color: #f8fafc;
        }
        
        .logo-text {
            background: linear-gradient(135deg, #3b82f6, #8b5cf6);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            font-weight: 700;
        }
        
        .flight-card {
            transition: all 0.3s ease;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        }
        
        .flight-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
        }
        
        .status-badge {
            padding: 0.25rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.75rem;
            font-weight: 600;
        }
        
        .tab-active {
            position: relative;
            color: #3b82f6;
            font-weight: 600;
        }
        
        .tab-active:after {
            content: "";
            position: absolute;
            bottom: -1px;
            left: 0;
            width: 100%;
            height: 3px;
            background: #3b82f6;
            border-radius: 3px 3px 0 0;
        }
        
        .airplane-icon {
            transform: rotate(90deg);
            color: #3b82f6;
        }
        
        .highlight {
            background-color: #FEF3C7;
            transition: background-color 0.3s;
        }
        
        .fade-in {
            animation: fadeIn 0.3s ease-in-out;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .flight-detail {
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease-out;
        }
        
        .flight-detail.open {
            max-height: 500px;
        }
        
        .date-picker {
            position: relative;
        }
        
        .date-picker input {
            padding-right: 2.5rem;
        }
        
        .date-picker i {
            position: absolute;
            right: 1rem;
            top: 50%;
            transform: translateY(-50%);
            pointer-events: none;
            color: #6b7280;
        }
        
        .search-box {
            position: relative;
        }
        
        .search-box i {
            position: absolute;
            left: 1rem;
            top: 50%;
            transform: translateY(-50%);
            color: #9ca3af;
        }
        
        .search-box input {
            padding-left: 2.5rem;
        }
        
        .user-avatar {
            background: linear-gradient(135deg, #3b82f6, #8b5cf6);
        }
        
        .admin-badge {
            background: linear-gradient(135deg, #f59e0b, #ef4444);
            color: white;
            font-size: 0.7rem;
            padding: 0.2rem 0.5rem;
            border-radius: 9999px;
            font-weight: 600;
        }
        
        .stats-card {
            transition: all 0.3s ease;
            border-radius: 0.75rem;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        }
        
        .stats-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
        }
        
        .dropdown-menu {
            display: none;
            position: absolute;
            right: 0;
            top: 100%;
            background-color: white;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            min-width: 200px;
            z-index: 10;
        }
        
        .dropdown-menu.open {
            display: block;
        }
        
        .dropdown-item {
            padding: 0.5rem 1rem;
            cursor: pointer;
            transition: background-color 0.2s;
        }
        
        .dropdown-item:hover {
            background-color: #f3f4f6;
        }
        
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 20;
            justify-content: center;
            align-items: center;
        }
        
        .modal.open {
            display: flex;
        }
        
        .modal-content {
            background-color: white;
            border-radius: 0.5rem;
            width: 90%;
            max-width: 500px;
            max-height: 90vh;
            overflow-y: auto;
            animation: modalFadeIn 0.3s ease-out;
        }
        
        @keyframes modalFadeIn {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .seat-map {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 0.5rem;
            margin-top: 1rem;
        }
        
        .seat {
            width: 40px;
            height: 40px;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 0.25rem;
            cursor: pointer;
            transition: all 0.2s;
        }
        
        .seat.available {
            background-color: #e5e7eb;
            color: #374151;
        }
        
        .seat.available:hover {
            background-color: #d1d5db;
        }
        
        .seat.selected {
            background-color: #3b82f6;
            color: white;
        }
        
        .seat.booked {
            background-color: #ef4444;
            color: white;
            cursor: not-allowed;
        }
        
        .seat.vip {
            background-color: #8b5cf6;
            color: white;
        }
        
        .seat.vip:hover {
            background-color: #7c3aed;
        }
    </style>
</head>
<body>
    <!-- Header -->
    <header class="bg-white shadow-sm sticky top-0 z-10">
        <div class="container mx-auto px-4 py-4 flex justify-between items-center">
            <div class="flex items-center space-x-2">
                <i class="fas fa-plane text-3xl text-blue-500"></i>
                <h1 class="text-2xl font-bold logo-text">花龙腾航</h1>
            </div>
            <nav class="hidden md:flex space-x-6">
                <a href="manager_index1" class="text-gray-600 hover:text-blue-500">主页</a>
                <a href="manager_flight_search1" class="text-gray-600 hover:text-blue-500">航班查询</a>
                <a href="manager_order" class="text-gray-600 hover:text-blue-500">订单管理</a>
                <a href="manager_flight" class="text-blue-500 font-medium">航班管理</a>
                <a href="manager_report" class="text-gray-600 hover:text-blue-500">报表统计</a>
            </nav>
            <div class="flex items-center space-x-4">
                <div class="relative">
                    <i class="fas fa-bell text-gray-500 text-xl cursor-pointer hover:text-blue-500"></i>
                    <span class="absolute top-0 right-0 h-2 w-2 rounded-full bg-red-500"></span>
                </div>
                <div class="flex items-center space-x-2 cursor-pointer group relative" id="user-menu">
                    <div class="h-8 w-8 rounded-full user-avatar flex items-center justify-center text-white">
                        <i class="fas fa-user-shield"></i>
                    </div>
                    <span class="hidden md:inline text-gray-700 group-hover:text-blue-500" th:text="${managername}">管理员</span>
                    <div class="dropdown-menu" id="dropdown-menu">
                        <div class="border-t border-gray-200 my-1"></div>
                        <div class="dropdown-item text-red-500" onclick="location.href='manager_logout'">
                            <i class="fas fa-sign-out-alt mr-2"></i> 退出登录
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="container mx-auto px-4 py-8">
        <div class="flex flex-col">
            <!-- Stats Cards -->
            <div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
                <div class="stats-card bg-white p-6 rounded-xl">
                    <div class="flex items-center justify-between">
                        <div>
                            <p class="text-sm text-gray-500">今日航班</p>
                            <h3 class="text-2xl font-bold text-gray-800" th:text="${flightCount}">42</h3>
                        </div>
                        <div class="p-3 rounded-full bg-blue-100 text-blue-500">
                            <i class="fas fa-plane"></i>
                        </div>
                    </div>
                    <!--div class="mt-2 text-sm text-green-500">
                        <i class="fas fa-arrow-up mr-1"></i> 5 较昨日
                    </div-->
                    <div class="mt-2 text-sm" th:classappend="${flightCountSign == 'negative'} ? 'text-red-500' : 'text-green-500'">
                        <i th:class="${flightCountSign == 'negative'} ? 'fas fa-arrow-down' : 'fas fa-arrow-up'" class="mr-1"></i>
                        <span th:text="'较昨日'+${flightCountCompare}"></span>
                    </div>
                </div>
                <div class="stats-card bg-white p-6 rounded-xl">
                    <div class="flex items-center justify-between">
                        <div>
                            <p class="text-sm text-gray-500">延误航班</p>
                            <h3 class="text-2xl font-bold text-gray-800" th:text="${delayFlightNum}">3</h3>
                        </div>
                        <div class="p-3 rounded-full bg-yellow-100 text-yellow-500">
                            <i class="fas fa-clock"></i>
                        </div>
                    </div>
                    <div class="mt-2 text-sm" th:classappend="${delayFlightNumSign == 'negative'} ? 'text-green-500' : 'text-red-500'">
                        <i th:class="${delayFlightNumSign == 'negative'} ? 'fas fa-arrow-down' : 'fas fa-arrow-up'" class="mr-1"></i>
                        <span th:text="'较昨日'+${delayFlightNumCompare}"></span>
                    </div>
                </div>
                <div class="stats-card bg-white p-6 rounded-xl">
                    <div class="flex items-center justify-between">
                        <div>
                            <p class="text-sm text-gray-500">可用座位</p>
                            <h3 class="text-2xl font-bold text-gray-800" th:text="${flightSpace}">1,248</h3>
                        </div>
                        <div class="p-3 rounded-full bg-green-100 text-green-500">
                            <i class="fas fa-chair"></i>
                        </div>
                    </div>
                    <div class="mt-2 text-sm" th:classappend="${flightSpaceSign == 'negative'} ? 'text-green-500' : 'text-red-500'">
                        <i th:class="${flightSpaceSign == 'negative'} ? 'fas fa-arrow-down' : 'fas fa-arrow-up'" class="mr-1"></i>
                        <span th:text="'较昨日'+${flightSpaceCompare}"></span>
                    </div>
                </div>
                <div class="stats-card bg-white p-6 rounded-xl">
                    <div class="flex items-center justify-between">
                        <div>
                            <p class="text-sm text-gray-500">取消航班</p>
                            <h3 class="text-2xl font-bold text-gray-800" th:text="${cancelFlightNum}">2</h3>
                        </div>
                        <div class="p-3 rounded-full bg-red-100 text-red-500">
                            <i class="fas fa-ban"></i>
                        </div>
                    </div>
                    <div class="mt-2 text-sm" th:classappend="${cancelFlightNumSign == 'negative'} ? 'text-green-500' : 'text-red-500'">
                        <i th:class="${cancelFlightNumSign == 'negative'} ? 'fas fa-arrow-down' : 'fas fa-arrow-up'" class="mr-1"></i>
                        <span th:text="'较昨日'+${cancelFlightNumCompare}"></span>
                    </div>
                </div>
            </div>

            <!-- Flight List -->
            <div class="bg-white rounded-xl shadow-sm overflow-hidden fade-in">
                <div class="p-6 border-b border-gray-100">
                    <div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
                        <div>
                            <h2 class="text-xl font-bold text-gray-800 mb-2">航班管理</h2>
                            <p class="text-sm text-gray-500">查看和管理所有航班信息</p>

                            <p th:if="${add_success}" style="color: green; font-size: 0.9em; margin-top: 0.5em;">航班添加成功！</p>
                            <p th:if="${add_failure}" style="color: red; font-size: 0.9em; margin-top: 0.5em;">航班添加失败！</p>
                            <p th:if="${delay_success}" style="color: green; font-size: 0.9em; margin-top: 0.5em;">延误操作成功！</p>
                            <p th:if="${delay_failure}" style="color: red; font-size: 0.9em; margin-top: 0.5em;">延误操作失败！</p>
                            <p th:if="${delete_success}" style="color: green; font-size: 0.9em; margin-top: 0.5em;">删除操作成功！</p>
                            <p th:if="${delete_failure}" style="color: red; font-size: 0.9em; margin-top: 0.5em;">删除操作失败！</p>
                            <p th:if="${edit_success}" style="color: green; font-size: 0.9em; margin-top: 0.5em;">编辑操作成功！</p>
                            <p th:if="${edit_failure}" style="color: red; font-size: 0.9em; margin-top: 0.5em;">编辑操作失败！</p>
                        </div>
                        <div class="flex space-x-2">
                            <button class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg flex items-center transition" onclick="openAddFlightModal()">
                                <i class="fas fa-plus mr-2"></i> 添加航班
                            </button>
                            <!--button class="px-4 py-2 bg-green-500 hover:bg-green-600 text-white rounded-lg flex items-center transition">
                                <i class="fas fa-download mr-2"></i> 导出数据
                            </button-->
                        </div>
                    </div>
                </div>

                <!-- Search and Filter -->
                <div class="p-6 border-b border-gray-100">
                    <div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
                        <div class="flex-1 flex flex-col md:flex-row gap-4">
                            <div class="search-box flex-1">
                                <i class="fas fa-search"></i>
                                <input type="text" id="searchInput" placeholder="搜索航班号、出发地或目的地..." class="w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                            </div>

                            <div class="date-picker">
                                <input type="date" id="dateFilter" class="border border-gray-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50">
                                <i class="fas fa-calendar-alt"></i>
                            </div>
                        </div>

                        <div class="flex space-x-2 w-full md:w-auto">
                            <select id="statusFilter" class="border border-gray-300 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50">
                                <option value="">所有状态</option>
                                <option value="upcoming">即将起飞</option>
                                <option value="scheduled">计划中</option>
                                <option value="departed">已起飞</option>
                                <option value="delayed">已延误</option>
                                <option value="cancelled">已取消</option>
                                <option value="arrived">已到达</option>
                            </select>
                            <button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg flex items-center transition" onclick="applyFilters()">
                                <i class="fas fa-filter mr-2"></i> 筛选
                            </button>
                        </div>
                    </div>
                </div>

                <!-- Flight List -->
                <div class="divide-y divide-gray-100" id="flight-list">
                    <!-- Flight items will be dynamically inserted here -->
                    <div class="flight-card bg-white transition duration-300" th:each="mflight : ${flightList}">
                        <div class="p-6">
                            <div class="flex justify-between items-start">
                                <div>
                                    <div class="flex items-center space-x-3 mb-2">
                                        <span class="font-medium text-gray-700" th:text="'航班号: '+${mflight.getFlight_id()}">航班号: HL888</span>
                                        <span class="text-gray-400">|</span>
                                        <span class="text-gray-500" th:text="${mflight.getDeparture_date()}+' '+${mflight.getDeparture_day()}">2023年11月15日</span>
                                    </div>
                                    <span class="status-badge"
                                          th:classappend="${mflight.getStatus() == '计划中'} ? 'bg-purple-100 text-purple-800' :
                                                           (${mflight.getStatus() == '即将起飞'} ? 'bg-green-100 text-green-800' :
                                                           (${mflight.getStatus() == '已起飞'} ? 'bg-blue-100 text-blue-800' :
                                                           (${mflight.getStatus() == '已延误'} ? 'bg-orange-100 text-orange-800' :
                                                           (${mflight.getStatus() == '已取消'} ? 'bg-red-100 text-red-800' :
                                                           'bg-yellow-100 text-yellow-800'))))"
                                          th:text="${mflight.getStatus()}">计划中
                                    </span>
                                </div>
                                <div class="text-right">
                                    <div class="text-xl font-bold text-blue-600" th:text="'¥'+${mflight.getEconomy_price()}+'(经济舱)&nbsp;&nbsp;'+'¥'+${mflight.getBusiness_price()}+'(商务舱)&nbsp;&nbsp;'+'¥'+${mflight.getFirst_price()}+'(头等舱)'">¥1280</div>
                                    <div class="text-sm text-gray-500" th:text="'剩余座位: '+'头等舱('+${mflight.getFirst_space()}+'/'+${mflight.getFirst_seat()}+')'+'&nbsp;&nbsp;商务舱('+${mflight.getBusiness_space()}+'/'+${mflight.getBusiness_seat()}+')'+'&nbsp;&nbsp;经济舱('+${mflight.getEconomy_space()}+'/'+${mflight.getEconomy_seat()}+')'">剩余座位: 42</div>
                                </div>
                            </div>

                            <div class="mt-4 flex items-center justify-between">
                                <div class="flex items-center space-x-4">
                                    <div class="text-center">
                                        <div class="text-xl font-bold" th:text="${mflight.getDeparture_city()}">北京</div>
                                        <div class="text-xs text-gray-500" th:text="${mflight.getDeparture_airport()}">(PEK)</div>
                                    </div>
                                    <div class="flex flex-col items-center">
                                        <div class="text-sm text-gray-500" th:text="${mflight.getDeparture_time()}">08:30</div>
                                        <div class="my-1 airplane-icon">
                                            <i class="fas fa-plane"></i>
                                        </div>
                                        <div class="text-sm text-gray-500" th:text="${mflight.getArrival_time()}">10:45</div>
                                    </div>
                                    <div class="text-center">
                                        <div class="text-xl font-bold" th:text="${mflight.getArrival_city()}">上海</div>
                                        <div class="text-xs text-gray-500" th:text="${mflight.getArrival_airport()}">(SHA)</div>
                                    </div>
                                </div>
                                <div class="text-sm text-gray-500">
                                    <i class="fas fa-plane mr-1"></i>
                                    <span class="text-gray-500" th:text="${mflight.getP_model()}"></span>
                                </div>
                            </div>

                            <div class="mt-4 flex justify-between items-center border-t border-gray-100 pt-4">
                                <div>
                                    <div class="text-xs text-gray-600">
                                        <i class="fas fa-info-circle mr-1"></i>
                                        <span class="text-sm text-gray-500" th:text="'预计飞行时间: '+${mflight.getDuration()}"></span>
                                    </div>
                                </div>

                                <div class="flex space-x-2">
                                    <a th:if="${mflight.getStatus()} == '已延误'"
                                       class="px-4 py-2 bg-green-500 hover:bg-green-600 text-white rounded-lg text-sm transition"
                                       th:href="'manager_flight_operation?f_id='+${mflight.flight_id}+'&action=arrival'">
                                        起飞
                                    </a>

                                    <a th:if="${mflight.getStatus()} == '已延误'"
                                       class="px-4 py-2 bg-green-500 hover:bg-green-600 text-white rounded-lg text-sm transition"
                                       th:href="'manager_flight_operation?f_id='+${mflight.flight_id}+'&action=arrival'">
                                        到达
                                    </a>
                                    <button th:if="${mflight.getStatus()} == '计划中' or ${mflight.getStatus()} == '即将起飞'"
                                            class="px-4 py-2 bg-yellow-500 hover:bg-yellow-600 text-white rounded-lg text-sm transition"
                                            th:attr="onclick=|confirmDelayFlight('${mflight.getFlight_id()}')|">
                                        延误
                                    </button>
                                    <a th:if="${mflight.getStatus()} == '计划中' or ${mflight.getStatus()} == '即将起飞' or ${mflight.getStatus()} == '已延误'"
                                       class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg text-sm transition"
                                       th:href="'manager_edit_flight?f_id='+${mflight.getFlight_id()}">
                                        <i class="fas fa-edit mr-1"></i> 编辑
                                    </a>
                                    <button class="px-4 py-2 bg-red-500 hover:bg-red-600 text-white rounded-lg text-sm transition"
                                            th:attr="onclick=|confirmDeleteFlight('${mflight.getFlight_id()}')|">
                                        <i class="fas fa-trash mr-1"></i> 删除
                                    </button>
                                    <button class="px-4 py-2 border border-gray-300 hover:bg-gray-50 rounded-lg text-sm transition flex items-center" onclick="toggleFlightDetail(this)">
                                        <span>查看详情</span>
                                        <i class="fas fa-chevron-down ml-1 text-xs transition-transform duration-200"></i>
                                    </button>
                                </div>
                            </div>

                            <!-- Flight Detail -->
                            <div class="flight-detail mt-4 border-t border-gray-100 pt-4">
                                <div class="grid grid-cols-1 md:grid-cols-4 gap-6">
                                    <div>
                                        <h4 class="font-medium text-gray-700 mb-2">航班信息</h4>
                                        <div class="space-y-2 text-sm text-gray-600">
                                            <div class="flex justify-between">
                                                <span>飞行距离:</span>
                                                <span class="font-medium" th:text="${mflight.getDistance()}+'km'">1800km</span>
                                            </div>
                                            <div class="flex justify-between">
                                                <span>登机口:</span>
                                                <span class="font-medium" th:text="${mflight.getGate() != null} ? ${mflight.getGate()} : '待定'">登机口: 待定</span>
                                            </div>
                                            <div class="flex justify-between">
                                                <span>行李额:</span>
                                                <span class="font-medium" th:text="${mflight.getBaggage_limit()}+'(经济舱)'"></span>
                                            </div>
                                            <div class="flex justify-between">
                                                <span>餐食:</span>
                                                <span class="font-medium" th:text="${mflight.getMeal_money()}+' - '+${mflight.getMeal()}"></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div>
                                        <h4 class="font-medium text-gray-700 mb-2">飞机信息</h4>
                                        <div class="space-y-2 text-sm text-gray-600">
                                            <div class="flex justify-between">
                                                <span>航司:</span>
                                                <span class="font-medium" th:text="${mflight.getP_airline()}"></span>
                                            </div>
                                            <div class="flex justify-between">
                                                <span>机龄:</span>
                                                <span class="font-medium" th:text="${mflight.getPlane_age()}">波音737-800</span>
                                            </div>
                                            <div class="flex justify-between">
                                                <span>座位数:</span>
                                                <span class="font-medium" th:text="${mflight.getCapacity()}+'&nbsp;&nbsp;('+${mflight.getFirst_seat()}+'头等舱/'+${mflight.getBusiness_seat()}+'商务舱/'+${mflight.getEconomy_seat()}+'经济舱'">162 (12商务舱/150经济舱)</span>
                                            </div>
                                            <div class="flex justify-between">
                                                <span>WiFi:</span>
                                                <span th:if="${mflight.getWiFi} == 'no'" class="font-medium">暂无提供</span>
                                                <span th:if="${mflight.getWiFi} == 'true'" class="font-medium">免费提供</span>
                                                <span th:if="${mflight.getWiFi} == 'pay'" class="font-medium">付费使用</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div>
                                        <h4 class="font-medium text-gray-700 mb-2">乘客统计</h4>
                                        <div class="space-y-2 text-sm text-gray-600">
                                            <div class="flex justify-between">
                                                <span>已预订:</span>
                                                <span class="font-medium" th:text="${mflight.getBookedSeat()}+'&nbsp;&nbsp;('+${mflight.getBookedSeatPercent()}+')'">120 (74%)</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div>
                                        <h4 class="font-medium text-gray-700 mb-2">机组人员</h4>
                                        <div class="space-y-2 text-sm text-gray-600">
                                            <div class="flex justify-between">
                                                <span>机长:</span>
                                                <span class="font-medium" th:text="${mflight.getCaptain()}">张伟</span>
                                            </div>
                                            <div class="flex justify-between">
                                                <span>副驾驶:</span>
                                                <span class="font-medium" th:text="${mflight.getAssistant_captain()}">李明</span>
                                            </div>
                                            <div class="flex justify-between">
                                                <span>乘务长:</span>
                                                <span class="font-medium" th:text="${mflight.getChief_attendant()}">王芳</span>
                                            </div>
                                            <div class="flex justify-between">
                                                <span>乘务员:</span>
                                                <span class="font-medium" th:text="${mflight.getFlight_crew_num()}">6人</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Empty State -->
                <div id="empty-state" class="hidden p-12 text-center">
                    <i class="fas fa-plane text-4xl text-gray-300 mb-4"></i>
                    <h3 class="text-lg font-medium text-gray-700">没有找到符合条件的航班</h3>
                    <p class="text-gray-500 mt-1">请尝试修改筛选条件或<a href="#" class="text-blue-500 hover:underline" onclick="openAddFlightModal()">添加新航班</a></p>
                </div>

                <!-- Pagination -->
                <div class="p-6 border-t border-gray-200 flex flex-col md:flex-row justify-between items-center gap-4">
                    <div class="text-sm text-gray-600">
                        显示 <span id="startItem" class="font-medium">1</span> 到 <span id="endItem" class="font-medium">3</span> 条，共 <span id="totalItems" class="font-medium">3</span> 条航班
                    </div>
                    <div class="flex items-center space-x-4">
                        <div class="flex items-center space-x-2">
                            <button id="prevPage" class="px-3 py-1.5 border border-gray-300 rounded-lg bg-white text-gray-700 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed flex items-center transition" disabled>
                                <i class="fas fa-chevron-left mr-1 text-xs"></i>
                                <span>上一页</span>
                            </button>
                            <div id="pageNumbers" class="flex space-x-1">
                                <button class="px-3 py-1 rounded-lg text-sm font-medium bg-blue-600 text-white">1</button>
                            </div>
                            <button id="nextPage" class="px-3 py-1.5 border border-gray-300 rounded-lg bg-white text-gray-700 hover:bg-gray-50 flex items-center transition disabled:opacity-50 disabled:cursor-not-allowed" disabled>
                                <span>下一页</span>
                                <i class="fas fa-chevron-right ml-1 text-xs"></i>
                            </button>
                        </div>
                        <div class="flex items-center space-x-2">
                            <span class="text-sm text-gray-600">每页显示</span>
                            <select id="pageSizeSelect" class="border border-gray-300 rounded-lg px-3 py-1.5 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50 text-sm">
                                <option value="5">5条</option>
                                <option value="10">10条</option>
                                <option value="15">15条</option>
                                <option value="20">20条</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <!-- Add Flight Modal -->
    <div class="modal" id="addFlightModal">
        <div class="modal-content">
            <div class="p-6 border-b border-gray-200 flex justify-between items-center">
                <h3 class="text-lg font-medium text-gray-800">添加新航班</h3>
                <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('addFlightModal')">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="p-6">
                <form id="addFlightForm" method="post" action="manager_add_flight">
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div>
                            <label for="Airline" class="block text-sm font-medium text-gray-700 mb-1">航司</label>
                            <select name="Airline" type="text" id="Airline" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                                <option value="">选择航司</option>
                                <option value="南方航空公司">南方航空公司</option>
                                <option value="东方航空公司">东方航空公司</option>
                                <option value="中国国际航空公司">中国国际航空公司</option>
                            </select>
                        </div>
                        <div>
                            <label for="aircraftType" class="block text-sm font-medium text-gray-700 mb-1">机型</label>
                            <input name="aircraftType" type="text" id="aircraftType" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50" placeholder="例如: 空客A320" required>
                        </div>
                        <div>
                            <label for="departureCity" class="block text-sm font-medium text-gray-700 mb-1">出发城市</label>
                            <input name="departureCity" type="text" id="departureCity" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50" placeholder="例如: 北京" required>
                        </div>
                        <div>
                            <label for="arrivalCity" class="block text-sm font-medium text-gray-700 mb-1">到达城市</label>
                            <input name="arrivalCity" type="text" id="arrivalCity" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50" placeholder="例如: 上海" required>
                        </div>
                        <div class="md:col-span-2">
                            <div>
                                <label for="departureAirport" class="block text-sm font-medium text-gray-700 mb-1">出发机场</label>
                                <input name="departureAirport" type="text" id="departureAirport" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50" placeholder="例如: 北京首都国际机场 (PEK)" required>
                            </div>
                        </div>
                        <div class="md:col-span-2">
                            <div>
                                <label for="arrivalAirport" class="block text-sm font-medium text-gray-700 mb-1">到达机场</label>
                                <input name="arrivalAirport" type="text" id="arrivalAirport" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50" placeholder="例如: 上海虹桥国际机场 (SHA)" required>
                            </div>
                        </div>
                        <div>
                            <label for="departureDate" class="block text-sm font-medium text-gray-700 mb-1">出发日期</label>
                            <input name="departureDate" type="date" id="departureDate" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="ArrivalDate" class="block text-sm font-medium text-gray-700 mb-1">到达日期</label>
                            <input name="ArrivalDate" type="date" id="ArrivalDate" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="departureTime" class="block text-sm font-medium text-gray-700 mb-1">出发时间</label>
                            <input name="departureTime" type="time" id="departureTime" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="arrivalTime" class="block text-sm font-medium text-gray-700 mb-1">到达时间</label>
                            <input name="arrivalTime" type="time" id="arrivalTime" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="flightStatus" class="block text-sm font-medium text-gray-700 mb-1">航班状态</label>
                            <select name="flightStatus" id="flightStatus" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50" required>
                                <option value="计划中">计划中</option>
                                <option value="登机中">登机中</option>
                                <option value="已起飞">已起飞</option>
                                <option value="已延误">已延误</option>
                                <option value="已取消">已取消</option>
                                <option value="已到达">已到达</option>
                            </select>
                        </div>
                        <div>
                            <label for="economyPrice" class="block text-sm font-medium text-gray-700 mb-1">经济舱价格</label>
                            <input name="economyPrice" type="number" id="economyPrice" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="¥" required>
                        </div>
                        <div>
                            <label for="businessPrice" class="block text-sm font-medium text-gray-700 mb-1">商务舱价格</label>
                            <input name="businessPrice" type="number" id="businessPrice" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="¥" required>
                        </div>
                        <div>
                            <label for="firstPrice" class="block text-sm font-medium text-gray-700 mb-1">头等舱价格</label>
                            <input name="firstPrice" type="number" id="firstPrice" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="¥" required>
                        </div>
                        <div>
                            <label for="distance" class="block text-sm font-medium text-gray-700 mb-1">飞行距离</label>
                            <input name="distance" type="number" id="distance" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="km" required>
                        </div>
                        <div>
                            <label for="Baggage" class="block text-sm font-medium text-gray-700 mb-1">行李额</label>
                            <input name="Baggage" type="number" id="Baggage" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="kg" required>
                        </div>
                        <div>
                            <label for="mealMoney" class="block text-sm font-medium text-gray-700 mb-1">餐食</label>
                            <select name="mealMoney" id="mealMoney" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50" required>
                                <option value="免费餐食">免费餐食</option>
                                <option value="付费餐食">付费餐食</option>
                                <option value="无提供">无提供</option>
                            </select>
                        </div>
                        <div>
                            <label for="mealType" class="block text-sm font-medium text-gray-700 mb-1">餐食类型</label>
                            <select name="mealType" id="mealType" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50" required>
                                <option value="早餐">早餐</option>
                                <option value="午餐">午餐</option>
                                <option value="晚餐">晚餐</option>
                                <option value="无提供">无提供</option>
                            </select>
                        </div>
                        <div>
                            <label for="WiFi" class="block text-sm font-medium text-gray-700 mb-1">WiFi</label>
                            <select name="WiFi" id="WiFi" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-gray-50" required>
                                <option value="true">免费使用</option>
                                <option value="pay">付费使用</option>
                                <option value="no">暂无提供</option>
                            </select>
                        </div>
                        <div>
                            <label for="gateNumber" class="block text-sm font-medium text-gray-700 mb-1">登机口</label>
                            <input name="gate" type="text" id="gateNumber" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="例如: A12" required>
                        </div>
                        <div>
                            <label for="buildDate" class="block text-sm font-medium text-gray-700 mb-1">飞机制造日期</label>
                            <input name="buildDate" type="date" id="buildDate" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="economySeat" class="block text-sm font-medium text-gray-700 mb-1">经济舱座位数</label>
                            <input name="economySeat" type="number" id="economySeat" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="businessSeat" class="block text-sm font-medium text-gray-700 mb-1">商务舱座位数</label>
                            <input name="businessSeat" type="number" id="businessSeat" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="firstSeat" class="block text-sm font-medium text-gray-700 mb-1">头等舱座位数</label>
                            <input name="firstSeat" type="number" id="firstSeat" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div class="md:col-span-2">
                            <label  class="block font-medium text-gray-700 mb-1">机组人员</label>
                        </div>
                        <div>
                            <label for="captain" class="block text-sm font-medium text-gray-700 mb-1">机长</label>
                            <input name="captain" type="text" id="captain" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="assistant_captain" class="block text-sm font-medium text-gray-700 mb-1">副机长</label>
                            <input name="assistant_captain" type="text" id="assistant_captain" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="chief_attendant" class="block text-sm font-medium text-gray-700 mb-1">乘务长</label>
                            <input name="chief_attendant" type="text" id="chief_attendant" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                        <div>
                            <label for="flight_crew_num" class="block text-sm font-medium text-gray-700 mb-1">机组人员数</label>
                            <input name="flight_crew_num" type="number" id="flight_crew_num" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required>
                        </div>
                    </div>

                    <div class="mt-8 flex justify-end space-x-3">
                        <button type="button" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition" onclick="closeModal('addFlightModal')">
                            取消
                        </button>
                        <button type="submit" class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg transition">
                            确认添加
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Delete Confirmation Modal -->
    <div class="modal" id="deleteModal">
        <div class="modal-content" style="max-width: 400px;">
            <div class="p-6 border-b border-gray-200 flex justify-between items-center">
                <h3 class="text-lg font-medium text-gray-800">确认删除</h3>
                <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('deleteModal')">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="p-6">
                <div class="text-center">
                    <i class="fas fa-exclamation-triangle text-4xl text-yellow-500 mb-4"></i>
                    <p class="text-gray-700 mb-6">确定要删除航班 <span id="flightToDelete" class="font-medium">888</span> 吗？此操作无法撤销。</p>
                    
                    <div class="flex justify-center space-x-3">
                        <button type="button" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition" onclick="closeModal('deleteModal')">
                            取消
                        </button>
                        <button type="button" class="px-4 py-2 bg-red-500 hover:bg-red-600 text-white rounded-lg transition" onclick="deleteFlight()">
                            确认删除
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Delay Confirmation Modal -->
    <div class="modal" id="delayModal">
        <div class="modal-content" style="max-width: 400px;">
            <div class="p-6 border-b border-gray-200 flex justify-between items-center">
                <h3 class="text-lg font-medium text-gray-800">确认延误</h3>
                <button class="text-gray-400 hover:text-gray-500" onclick="closeModal('delayModal')">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="p-6">
                <div class="text-center">
                    <i class="fas fa-exclamation-triangle text-4xl text-yellow-500 mb-4"></i>
                    <p class="text-gray-700 mb-6">确定要将航班 <span id="flightToDelay" class="font-medium">HL888</span> 设置为“已延误”吗？此操作不可逆。</p>

                    <div class="flex justify-center space-x-3">
                        <button type="button" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition" onclick="closeModal('delayModal')">
                            取消
                        </button>
                        <button type="button" class="px-4 py-2 bg-yellow-500 hover:bg-yellow-600 text-white rounded-lg transition" onclick="delayFlight()">
                            确认延误
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- Footer -->
    <footer class="bg-gray-50 mt-12">
        <div class="container mx-auto px-4 py-8">
            <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
                <div>
                    <div class="flex items-center space-x-2 mb-4">
                        <i class="fas fa-plane text-2xl text-blue-500"></i>
                        <h3 class="text-xl font-bold logo-text">花龙腾航</h3>
                    </div>
                    <p class="text-gray-600 text-sm">花龙腾航，让您的每一次飞行都成为美好回忆。我们致力于提供安全、舒适、便捷的航空服务。</p>
                </div>
                <div>
                    <h4 class="font-bold text-gray-800 mb-4">关于我们</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li><a href="public_company_profile" class="hover:text-blue-500 transition">公司简介</a></li>
                        <li><a href="public_company_profile" class="hover:text-blue-500 transition">企业文化</a></li>
                        <li><a href="public_company_profile" class="hover:text-blue-500 transition">发展历程</a></li>
                        <li><a href="public_job_posting" class="hover:text-blue-500 transition">招贤纳士</a></li>
                    </ul>
                </div>
                <div>
                    <h4 class="font-bold text-gray-800 mb-4">帮助中心</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li><a href="public_faq" class="hover:text-blue-500 transition">常见问题</a></li>
                        <li><a href="public_baggage_regulations" class="hover:text-blue-500 transition">行李规定</a></li>
                        <li><a href="public_company_profile" class="hover:text-blue-500 transition">航班动态</a></li>
                        <li><a href="public_callus" class="hover:text-blue-500 transition">联系客服</a></li>
                    </ul>
                </div>
                <div>
                    <h4 class="font-bold text-gray-800 mb-4">联系我们</h4>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li class="flex items-center"><i class="fas fa-phone-alt mr-2 text-blue-500"></i> 客服热线: 19976338635</li>
                        <li class="flex items-center"><i class="fas fa-envelope mr-2 text-blue-500"></i> ganshenghao888@qq.com</li>
                        <li class="flex items-center"><i class="fas fa-map-marker-alt mr-2 text-blue-500"></i> 广东省广州市天河区华南农业大学</li>
                    </ul>
                    <div class="flex space-x-4 mt-4">
                        <a href="https://weixin.com" class="h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center text-blue-500 hover:bg-blue-200 transition">
                            <i class="fab fa-weixin"></i>
                        </a>
                        <a href="https://weibo.com" class="h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center text-blue-500 hover:bg-blue-200 transition">
                            <i class="fab fa-weibo"></i>
                        </a>
                        <a href="https://qq.com" class="h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center text-blue-500 hover:bg-blue-200 transition">
                            <i class="fab fa-qq"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="border-t border-gray-200 mt-8 pt-6 text-center text-sm text-gray-500">
                <p>© 2025 花龙腾航航空公司 版权所有 | 京ICP备12345678号</p>
            </div>
        </div>
    </footer>

    <script>
        // Current page and page size
        let currentPage = 1;
        let pageSize = parseInt(localStorage.getItem('pageSize')) || 5;
        let currentFilter = 'all';
        let allFlights = Array.from(document.querySelectorAll('.flight-card'));
        let flightToDelete = '';

        // DOM elements
        const flightList = document.getElementById('flight-list');
        const emptyState = document.getElementById('empty-state');
        const searchInput = document.getElementById('searchInput');
        const dateFilter = document.getElementById('dateFilter');
        const statusFilter = document.getElementById('statusFilter');
        const prevPageBtn = document.getElementById('prevPage');
        const nextPageBtn = document.getElementById('nextPage');
        const pageNumbers = document.getElementById('pageNumbers');
        const startItem = document.getElementById('startItem');
        const endItem = document.getElementById('endItem');
        const totalItems = document.getElementById('totalItems');
        const pageSizeSelect = document.getElementById('pageSizeSelect');
        const addFlightModal = document.getElementById('addFlightModal');
        const deleteModal = document.getElementById('deleteModal');
        const flightToDeleteElement = document.getElementById('flightToDelete');
        const addFlightForm = document.getElementById('addFlightForm');

        // Initialize page
        function init() {
            // Set the saved page size
            pageSizeSelect.value = pageSize;
            applyFilters();
            addEventListeners();
        }

        // Apply all filters (status, search, date)
        function applyFilters() {
            const searchTerm = searchInput.value.toLowerCase();
            const selectedDate = dateFilter.value;
            const selectedStatus = statusFilter.value;

            // Get all flight elements
            allFlights = Array.from(document.querySelectorAll('.flight-card'));

            let visibleFlights = allFlights.filter(flight => {
                const flightNo = flight.querySelector('.font-medium').textContent.toLowerCase();
                const fromCity = flight.querySelector('.text-center:first-child .text-xl').textContent.toLowerCase();
                const toCity = flight.querySelector('.text-center:last-child .text-xl').textContent.toLowerCase();
                const flightDate = flight.querySelector('.text-gray-500').textContent;
                const status = flight.querySelector('.status-badge').textContent;

                // Status filter
                const matchesStatus = selectedStatus === '' || 
                    (selectedStatus === 'scheduled' && status === '计划中') ||
                    (selectedStatus === 'upcoming' && status === '即将起飞') ||
                    (selectedStatus === 'departed' && status === '已起飞') ||
                    (selectedStatus === 'delayed' && status === '已延误') ||
                    (selectedStatus === 'cancelled' && status === '已取消') ||
                    (selectedStatus === 'arrived' && status === '已到达');

                // Search term - matches flight number, departure or arrival city
                const matchesSearch = searchTerm === '' || 
                    flightNo.includes(searchTerm) || 
                    fromCity.includes(searchTerm) || 
                    toCity.includes(searchTerm);

                // Date filter
                const formattedFlightDate = flightDate.replace(/(\d{4})年(\d{2})月(\d{2})日/, '$1-$2-$3');
                const matchesDate = selectedDate === '' || 
                    formattedFlightDate.includes(selectedDate);

                return matchesStatus && matchesSearch && matchesDate;
            });

            // Update total items count
            totalItems.textContent = visibleFlights.length;

            // Show empty state if no flights match
            if (visibleFlights.length === 0) {
                emptyState.classList.remove('hidden');
            } else {
                emptyState.classList.add('hidden');
            }

            // Reset to first page when filters change
            currentPage = 1;
            renderPagination(visibleFlights);
        }

        // Change page size
        function changePageSize(newSize) {
            pageSize = parseInt(newSize);
            // Save to localStorage
            localStorage.setItem('pageSize', pageSize);
            currentPage = 1;
            applyFilters();
        }

        // Toggle flight detail visibility
        function toggleFlightDetail(button) {
            const flightCard = button.closest('.flight-card');
            const detailSection = flightCard.querySelector('.flight-detail');
            const chevron = button.querySelector('i');

            detailSection.classList.toggle('open');
            chevron.classList.toggle('transform');
            chevron.classList.toggle('rotate-180');
        }

        // Open add flight modal
        function openAddFlightModal() {
            addFlightModal.classList.add('open');
        }

        // Close modal
        function closeModal(modalId) {
            document.getElementById(modalId).classList.remove('open');
        }

        // Confirm delete flight
        function confirmDeleteFlight(flightNumber) {
            flightToDelete = flightNumber;
            flightToDeleteElement.textContent = flightNumber;
            deleteModal.classList.add('open');
        }

        function deleteFlight() {
            if (!flightToDelete) {
                alert("未指定要删除的航班号");
                return;
            }

            // 使用 fetch 发送 POST 请求到后端
            fetch('manager_delete_flight', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                body: 'flightId=' + encodeURIComponent(flightToDelete)
            })
                .then(response => {
                    if (response.ok) {
                        return response.text(); // 或者返回 json 如果后端返回 JSON
                    }
                    throw new Error('网络响应异常');
                })
                .then(data => {
                    console.log('删除成功:', data);
                    alert(`航班 ${flightToDelete} 已成功删除！`);
                    closeModal('deleteModal');
                    window.location.reload(); // 刷新页面以更新列表
                })
                .catch(error => {
                    console.error('删除失败:', error);
                    alert('删除失败，请查看控制台日志');
                });
        }

        let flightToDelay = '';

        // 打开延误确认弹窗
        function confirmDelayFlight(flightNumber) {
            flightToDelay = flightNumber;
            document.getElementById('flightToDelay').textContent = flightNumber;
            document.getElementById('delayModal').classList.add('open');
        }

        // 提交延误请求
        function delayFlight() {
            if (!flightToDelay) {
                alert("未指定要延误的航班号");
                return;
            }

            // 使用 fetch 发送 POST 请求到后端
            fetch('manager_delay_flight', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                body: 'flightId=' + encodeURIComponent(flightToDelay)
            })
                .then(response => {
                    if (response.ok) {
                        return response.text(); // 或者返回 json 如果后端返回 JSON
                    }
                    throw new Error('网络响应异常');
                })
                .then(data => {
                    console.log('延误成功:', data);
                    alert(`航班 ${flightToDelay} 已标记为延误`);
                    closeModal('delayModal');
                    window.location.reload(); // 刷新页面以更新列表
                })
                .catch(error => {
                    console.error('延误失败:', error);
                    alert('操作失败，请查看控制台日志');
                });
        }

        /*
        // Handle add flight form submission
        addFlightForm.addEventListener('submit', function(e) {
            e.preventDefault();

            // Get form values
            const flightNumber = document.getElementById('flightNumber').value;
            const aircraftType = document.getElementById('aircraftType').value;
            const departureCity = document.getElementById('departureCity').value;
            const arrivalCity = document.getElementById('arrivalCity').value;
            const departureDate = document.getElementById('departureDate').value;
            const departureTime = document.getElementById('departureTime').value;
            const arrivalTime = document.getElementById('arrivalTime').value;
            const flightStatus = document.getElementById('flightStatus').value;
            const basePrice = document.getElementById('basePrice').value;
            const gateNumber = document.getElementById('gateNumber').value;
            const flightNotes = document.getElementById('flightNotes').value;

            // In a real application, this would make an AJAX call to the backend
            alert(`航班 ${flightNumber} 已添加！\n在实际应用中会发送数据到服务器`);

            // Close modal and reset form
            closeModal('addFlightModal');
            this.reset();

            // Reload the page to reflect changes
            window.location.reload();
        });
         */

        // Handle seat selection
        document.querySelectorAll('.seat.available').forEach(seat => {
            seat.addEventListener('click', function() {
                this.classList.toggle('selected');
            });
        });

        // Render pagination controls
        function renderPagination(visibleFlights) {
            const totalPages = Math.ceil(visibleFlights.length / pageSize);

            // Update prev/next buttons
            prevPageBtn.disabled = currentPage === 1;
            nextPageBtn.disabled = currentPage === totalPages || totalPages === 0;

            // Clear page numbers
            pageNumbers.innerHTML = '';

            // Calculate range of pages to show
            let startPage = Math.max(1, currentPage - 2);
            let endPage = Math.min(totalPages, currentPage + 2);

            // Ensure we show 5 pages if possible
            if (endPage - startPage < 4) {
                if (currentPage < totalPages / 2) {
                    endPage = Math.min(startPage + 4, totalPages);
                } else {
                    startPage = Math.max(endPage - 4, 1);
                }
            }

            // Add first page button
            if (startPage > 1) {
                addPageButton(1, visibleFlights);
                if (startPage > 2) {
                    const ellipsis = document.createElement('span');
                    ellipsis.className = 'px-3 py-1';
                    ellipsis.textContent = '...';
                    pageNumbers.appendChild(ellipsis);
                }
            }

            // Add page buttons
            for (let i = startPage; i <= endPage; i++) {
                addPageButton(i, visibleFlights);
            }

            // Add last page button
            if (endPage < totalPages) {
                if (endPage < totalPages - 1) {
                    const ellipsis = document.createElement('span');
                    ellipsis.className = 'px-3 py-1';
                    ellipsis.textContent = '...';
                    pageNumbers.appendChild(ellipsis);
                }
                addPageButton(totalPages, visibleFlights);
            }

            // Update pagination info
            const startIndex = (currentPage - 1) * pageSize;
            const endIndex = Math.min(startIndex + pageSize, visibleFlights.length);

            startItem.textContent = startIndex + 1;
            endItem.textContent = endIndex;
            totalItems.textContent = visibleFlights.length;

            // Show/hide flights based on current page
            allFlights.forEach(flight => flight.style.display = 'none');
            visibleFlights.forEach((flight, index) => {
                if (index >= startIndex && index < endIndex) {
                    flight.style.display = '';
                }
            });
        }

        // Add a page button
        function addPageButton(page, visibleFlights) {
            const button = document.createElement('button');
            button.className = `px-3 py-1 rounded-lg text-sm font-medium ${currentPage === page ? 'bg-blue-600 text-white' : 'bg-white text-gray-700 hover:bg-gray-50'}`;
            button.textContent = page;
            button.addEventListener('click', () => {
                currentPage = page;
                renderPagination(visibleFlights);
                window.scrollTo({ top: 0, behavior: 'smooth' });
            });
            pageNumbers.appendChild(button);
        }

        // Add event listeners
        function addEventListeners() {
            // Search input
            searchInput.addEventListener('input', () => {
                applyFilters();
            });

            // Date filter
            dateFilter.addEventListener('change', () => {
                applyFilters();
            });

            // Status filter
            statusFilter.addEventListener('change', () => {
                applyFilters();
            });

            // Previous page
            prevPageBtn.addEventListener('click', () => {
                if (currentPage > 1) {
                    currentPage--;
                    applyFilters();
                    window.scrollTo({ top: 0, behavior: 'smooth' });
                }
            });

            // Next page
            nextPageBtn.addEventListener('click', () => {
                const visibleFlights = allFlights.filter(flight => flight.style.display !== 'none');
                const totalPages = Math.ceil(visibleFlights.length / pageSize);

                if (currentPage < totalPages) {
                    currentPage++;
                    applyFilters();
                    window.scrollTo({ top: 0, behavior: 'smooth' });
                }
            });

            // Page size selector
            pageSizeSelect.addEventListener('change', (e) => {
                changePageSize(e.target.value);
            });
        }

        // Initialize the page
        document.addEventListener('DOMContentLoaded', init);

        // Toggle user dropdown menu
        document.getElementById('user-menu').addEventListener('click', function(event) {
            event.stopPropagation(); // 防止点击事件冒泡
            document.getElementById('dropdown-menu').classList.toggle('open');
        });

        // Close dropdown when clicking outside
        document.addEventListener('click', function(event) {
            const dropdown = document.getElementById('dropdown-menu');
            const userMenu = document.getElementById('user-menu');

            if (!userMenu.contains(event.target) && !dropdown.contains(event.target)) {
                dropdown.classList.remove('open');
            }
        });
    </script>
</body>
</html>